TWebBrowser loadfromstream

Otázka od: Bronislav Klucka

5. 8. 2004 21:07

Zdar,
potreboval bych zobrazit HTML stranku, kterou mam pouze ve stringu (resp.
streamu), jak donutit TWebBrowser, aby mi toto vyrendroval?


Brona


Odpovedá: Lukas Gebauer

6. 8. 2004 7:55

> potreboval bych zobrazit HTML stranku, kterou mam pouze ve stringu
> (resp. streamu), jak donutit TWebBrowser, aby mi toto vyrendroval?

Zrovna vcera vecer jsem to programoval.  

WebBrowser.document musi pred volanim existovat! Ten objekt dokumentu
se totiz vytvari az pote, co se neco zobrazi. Toho docilis treba pres
webbrowser.navigate('about:blank'). Jo, a asi to bude chtit pridat do
uses unitu ActiveX!)

procedure WBLoadHTML(WebBrowser: TWebBrowser; Filename: string) ;
var
  ms: TMemoryStream;
  FileStream: TFileStream;
Begin
  if Assigned(WebBrowser.Document) then
  begin
    FileStream := TFileStream.Create(FileName, fmOpenRead + fmShareDenyWrite);
    try
      (WebBrowser.Document as
IPersistStreamInit).Load(TStreamAdapter.Create(FileStream)) ;
    finally
      FileStream.Free;
    end;
  end;
end;
 


--
Lukas Gebauer.

E-mail: gebauerl@mlp.cz
http://www.ararat.cz/synapse/ - Ararat Synapse - TCP/IP Lib.


Odpovedá: Pavel Benacek

6. 8. 2004 9:49

On Thu, 5 Aug 2004 21:48:27 +0200, Bronislav Klucka
<bronislav.klucka@pro2-soft.com> wrote:

> Zdar,
> potreboval bych zobrazit HTML stranku, kterou mam pouze ve stringu (resp.
> streamu), jak donutit TWebBrowser, aby mi toto vyrendroval?
>
>
> Brona
>

uses ActiveX;

procedure WBLoadFromStream(WebBrowser: TWebBrowser; Stream: TStream);
var
   PersistStreamInit: IPersistStreamInit;
   StreamAdapter: IStream;
   MemoryStream: TMemoryStream;
begin
   WebBrowser.Navigate('about:blank');
   repet
     Application.ProcessMessages;
     Sleep(0);
   until (WebBrowser.ReadyState = READYSTATE_COMPLETE);
   if WebBrowser.Document.QueryInterface(IPersistStreamInit,
PersistStreamInit) = S_OK then
   begin
     if PersistStreamInit.InitNew = S_OK then
     begin
       MemoryStream := TMemoryStream.Create;
       try
         MemoryStream.CopyFrom(Stream, 0);
         MemoryStream.Position := 0;
       except
         MemoryStream.Free;
         raise;
       end;
       StreamAdapter := TStreamAdapter.Create(MemoryStream, soOwned);
       PersistStreamInit.Load(StreamAdapter);
     end;
   end;
end;

Zdroj: 1001 TIPU A TRIKU PRO DELPHI